//
//  CheckPhoneController.m
//  WuJieLive
//
//  Created by 张瀚坤 on 2017/11/8.
//  Copyright © 2017年 zhk. All rights reserved.
//

#import "CheckPhoneController.h"
#import "MyCardController.h"

@interface CheckPhoneController ()
@property (weak, nonatomic) IBOutlet UITextField *teleNumText;
@property (weak, nonatomic) IBOutlet UITextField *codeText;

@end

@implementation CheckPhoneController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
}

-(void)setNavi
{
    self.title = @"绑定银行卡";
}

-(void)setUI
{
    self.view.backgroundColor = Color(245, 245, 245);
    self.doneBtn.layer.masksToBounds = YES;
    self.doneBtn.layer.cornerRadius = 20;
    self.getCodeBtn.layer.borderWidth = 0.5;
    self.getCodeBtn.layer.masksToBounds = YES;
    self.getCodeBtn.layer.cornerRadius = 15;
    self.getCodeBtn.layer.borderColor = TextLessImportColor.CGColor;
}

- (IBAction)getCodeAction:(UIButton *)sender {
    [self openCountdown];
}

// 开启倒计时效果
-(void)openCountdown{
    
    if ( self.teleNumText.text.length == 11) {
        [MBProgressHUD showHUDAddedTo:self.view animated:YES];
        NSDictionary * dict = @{@"token":self.userToken,@"phone":self.teleNumText.text};
        [HTTPTool POSTForm:[NSString stringWithFormat:@"%@bank-bind/add-bank-card-save",BaseUrl] para:dict success:^(BOOL isSuccess, id responseObject) {
            [MBProgressHUD hideHUDForView:self.view animated:YES];
            if (isSuccess) {
                [self.getCodeBtn startWithTime:59 title:@"获取验证码" countDownTitle:@"重新发送" mainColor:[UIColor clearColor] countColor:[UIColor clearColor]];
            }
        } failure:^(NSError *error) {
            [MBProgressHUD hideHUDForView:self.view animated:YES];
        }];
    }
}

- (IBAction)doneAction:(id)sender {
   if (self.codeText.text.length == 6 && self.teleNumText.text.length == 11) {
       [MBProgressHUD showHUDAddedTo:self.view animated:YES];
       NSDictionary * dict = @{@"toekn":self.userToken,@"sms_code":self.codeText.text};
       [HTTPTool POSTForm:[NSString stringWithFormat:@"%@bank-bind/add-bank-card-save",BaseUrl] para:dict success:^(BOOL isSuccess, id responseObject) {
           [MBProgressHUD hideHUDForView:self.view animated:YES];
           if (isSuccess) {
               [MBProgressHUD showSuccess:@"绑定完成!"];
               dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
                   [self.navigationController popToRootViewControllerAnimated:YES];
               });
           }
       } failure:^(NSError *error) {
           [MBProgressHUD hideHUDForView:self.view animated:YES];
       }];
   }
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
